#ifndef MULTIEDITOR_H
#define MULTIEDITOR_H

#include <QtGui/QTabWidget>
#include <QtGui/QTabBar>
#include <QtCore/QList>
#include "Editor.h"

class TabsWidget : public QTabWidget
{
	public:
		TabsWidget(QWidget *parent) : QTabWidget(parent) {}
		void showTabBar(bool show) {
			tabBar()->setVisible(show);
		}
};

class Editor;

typedef QList<Editor *> EditorsList;

class MultiEditor : public QObject
{
	Q_OBJECT
	signals:
		void currentEditorChanged(Editor *currentEditor);
		void contextMenuCalled(int globalX,int globalY);
		void currentTabTextChanged(const QString& tabText);
		void currentTabCloseRequested();
	public slots:
		void previousEditor();
		void nextEditor();
		
		void setTabsVisible(bool isVisible);
		
		void undo();
		void redo();
		void cut();
		void copy();
		void paste();
		void selectAll();
		void commentSelectedText();
		void unindentSelectedLines();
	
		void addEditor(const QString& tabTitle = QString());
		void closeEditor(int editorIndex);
		void closeCurrentEditor();

		void openFirstTab();
		
		void goToLineInCurrentEditor(int line);
		
		void changeEolMode(int eolIndex);
		
		void setEditorModification(int editorIndex,bool isModified);
		void setTabText(int tabIndex,const QString& text);
		void setCurrentEditorModification(bool isModified);
		void setCurrentTabText(const QString& text);
		void showOpenedFilesList(bool show);
	public:
		MultiEditor(QWidget *parent = 0);
		~MultiEditor();
	
		void moveToEditorWithName(const QString& editorName);
	
		int count();
		int getCurrentIndex();
		
		int getLinesCountOfCurrentEditor();
	
		QString getCurrentTabText() const;
		
		Editor* getEditor(int editorIndex) const;
		Editor* getCurrentEditor() const;
		const EditorsList& getOpenedEditors() const;
	
		void showTabBarWhenOpenedOneEditor(bool show);
		
		QTabWidget* getTabWidget() const;
	private slots:
		void currentIndexChanged(int currentIndex);
		void closeTabByRequest(int index);
	private:
		// Hide or show tabs bar
		void updateTabsBarStatus();
	
		EditorsList openedEditors;
		Editor *currentEditor;
	
		TabsWidget *tabWidget;
		bool showFilesList;
		bool showTabBarWithOneTab;
		
		bool areTabsVisible;
		
		int previousEditorIndex;
		QsciScintilla::EolMode currentEolMode;
		bool firstOpenedEditor;
};

#endif
